<!--------------------------------------------------------------
>//	Company:	HTHK
>//	NAME:	    DaySpendExport.jsp
>//	BY:	        Beyes Xia
>//	DATE:	    2004-4-19 13:07
>// --------------------------------------------------------------
-->

<%@ include file="../tssheader.jsp" %>
<%@ page import="tss.options.*" %>
<script Language="Javascript" src="<%=contextPath%>/tss/dayspendreport/Calendar1-821.js"></script>
<%
   	try
	{
		StaffOptions staffOption = new StaffOptions();
		ProjectOptions projectOption = new ProjectOptions();
		String str_staffName = session.getAttribute("s_staff_name")==null?"":(String)session.getAttribute("s_staff_name");
		String str_projectName = session.getAttribute("s_project_name")==null?"":(String)session.getAttribute("s_project_name");
		String str_dateFrom = session.getAttribute("s_date_from")==null?"":(String)session.getAttribute("s_date_from");
		String str_dateTo = session.getAttribute("s_date_to")==null?"":(String)session.getAttribute("s_date_to");
%>

<script language="JavaScript1.1">
function mySubmit()
{
	if(checkDate(fm.date_from) && checkDate(fm.date_to) && checkFromTO())
	{
		fm.submit();
	}
}
function myReset()
{
	fm.staff_name.options[0].selected = true;
	fm.project_name.options[0].selected = true;
	fm.date_from.value = "";
	fm.date_to.value = "";
}
function tss_calendar_from()
{
	var today = new Date();
	show_calendar('fm.date_from', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function tss_calendar_to()
{
	var today = new Date();
	show_calendar('fm.date_to', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function checkFromTO()
{
	if(fm.date_from.value.length!=0 && fm.date_to.value.length!=0 && fm.date_from.value>fm.date_to.value)
	{
		alert("Date From must be earlier than Date To");
		return false;
	}
	return true;
}
function checkDate(object) 
{
	var obj=object;
	var d = obj.value;
	if(d.length!=0 && d.length !=10)
	{
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
	}	
	if(d.length==10)
	{
		if (d.substring(4,5)!="-" || d.substring(7,8)!="-") 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		var day = d.substring(8,10);
		var month = d.substring(5,7);
		var year = d.substring(0,4);
		if (day==null || isNaN(day)) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (month==null || isNaN(month)) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (day==null || isNaN(day)) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (day < 1 || day > 31)
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (month < 1 || month > 12) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (month == 2) 
		{
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap))
			{
				alert("Please input correct date with format as YYYY-MM-DD.");
				return false;
			}
		} 
	}
	return true;
}
</script>

<body>
<h2>Everyday Spend Report</h2>
<form id=fm method=post action='<%=contextPath%>/servlet/tss.dayspendreport.DaySpendSearch' >
<table cols=4 >
<tr>
	<td><b>Staff Name: </b></td>
	<td>
		<select name=staff_name style="width:140;">
			<%=staffOption.getOptions(str_staffName,false)%>
		</select>
	</td>
</tr>
<tr>
	<td><b>Project Name: </b></td>
	<td>
		<select name=project_name style="width:140;">
			<%=projectOption.getOptions(str_projectName,false)%>
		</select>
	</td>
</tr>
<tr>
	<td width='20%'><b>Date Range:</b></td>
	<td >From :&nbsp;
	<input type=text name='date_from'  maxlength=10  align='left' value='<%= str_dateFrom %>'>
	<input type=button name=but_cal onClick="tss_calendar_from();" value='...'>(YYYY-MM-DD)*</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td >To :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type=text name='date_to'  maxlength=10  align='left' value='<%= str_dateTo %>'>
	<input type=button name=but_cal1 onClick="tss_calendar_to();" value='...'>(YYYY-MM-DD)*</td>
</tr>
</table>
<br>
<hr>
<p>
  <INPUT type=button value='Export' onclick='mySubmit()'>
  <INPUT type=button value='Cancel' onclick='myReset()'>
</p>
</form>
<%  
	}
	catch(Exception e)
	{
		out.println(e.toString());
	}
%>
<%@ include file="../tssfooter.jsp" %>
</body>
</html>

